/**
 * @Description : 用户信息表
 **/
const mongoose = require("mongoose");
const publicId = require("mongoose-public-id"); //自动生成容易识别的编码
const userSchema = new mongoose.Schema(
    {
        id: {
            //自动生成编码
            type: String,
            required: true,
            unique: true,
            default: ""
        },
        account: {
            //登录账号
            type: String,
            required: true,
            minlength: ["5", "登录账号不能小于5个字符"],
            maxlength: ["20", "登录账号不能大于20个字符"]
        },
        password: {
            //登录账号密码
            type: String,
            required: false,
            minlength: ["6", "登录账号密码不能小于6个字符"],
            maxlength: ["50", "登录账号密码不能大于50个字符"]
        },
        nick_name: {
            //昵称
            type: String,
            required: false,
            default: ""
        },
        folder_list: [
            //用户文件夹列表
            {
                id: {
                    //文件夹ID
                    type: String,
                    required: false,
                    default: ""
                },
                parent_id: {
                    //所属文件夹，为空表示根目录
                    type: String,
                    required: false,
                    default: ""
                },
                folder_name: {
                    //文件夹名称
                    type: String,
                    required: false,
                    default: ""
                },
                folder_memo: {
                    //文件夹备注
                    type: String,
                    required: false,
                    default: ""
                },
                folder_status: {
                    //数据记录状态（标志位）：0，删除；1，正常
                    type: Number,
                    required: true,
                    default: 1
                },
                folder_update_time: {
                    //更新时间
                    type: String,
                    required: false,
                    default: ""
                }
            }
        ],
        memo: {
            //备注
            type: String,
            required: false,
            default: ""
        },
        status: {
            //数据记录状态（标志位）：0，删除；1，正常
            type: Number,
            required: true,
            default: 1
        },
        create_user: {
            //创建人
            type: String,
            required: true
        },
        create_time: {
            //创建时间
            type: String,
            required: true
        },
        update_user: {
            //更新人
            type: String,
            required: false,
            default: ""
        },
        update_time: {
            //更新时间
            type: String,
            required: false,
            default: ""
        },
        delete_user: {
            //删除人
            type: String,
            required: false,
            default: ""
        },
        delete_time: {
            //删除记录时间
            type: String,
            required: false,
            default: ""
        }
    },
    { versionKey: false }
);
userSchema.index({ account: 1 }, { unique: true });
userSchema.index({ status: 1 });
userSchema.plugin(publicId, {
    //定义自动编码的组件
    namespace: "ur",
    prefix: "_",
    fieldName: "id",
    index: true
});
module.exports = mongoose.model("users", userSchema, "users"); // 参数:1,模型名称;2,对象;3,集合名称(collecttion)
